Ext.define('Admin.view.organization.OrganizationForm', {
    extend: 'Ext.form.Panel',
    alias: 'widget.organizationForm',
    xtype: 'organizationForm',

    requires: [
        'Admin.model.user.User',
        'Ext.form.field.Text',
        'Ext.button.Button'
    ],

    controller: 'organizationViewController',

    defaultType: 'textfield',

    layout: {
        type: 'vbox',
        align: 'stretch'
    },

    items: [{
            fieldLabel: '部门名',
            name: 'name',
            allowBlank: false,
            blankText: '此项不能为空'
        }, {
            xtype: 'combobox',
            fieldLabel: '负责人',
            name: 'lead',
            allowBlank: true,
            displayField: 'fullname',
            valueField: 'id',
            listeners: {
                focus: function() {
                    var form = this.up('form').getForm();
                    var record = form.getRecord();
                    var store = Ext.create('Admin.store.user.OrganizationUserStore')
                    Ext.apply(store.proxy.extraParams, {
                        deptId: record.data.id
                    })
                    this.setStore(store);
                }
            }
        },
        {
            xtype: 'combobox',
            fieldLabel: '从属部门',
            name: 'parent',
            displayField: 'name',
            valueField: 'id',
            allowBlank: true,
            store: Ext.create('Admin.store.organization.OrganizationStore')
        }
    ],

    buttons: ['->', {
        text: '取消',
        listeners: {
            click: 'onFormCancelButton'
        }
    }, {
        text: '修改',
        formBind: true,
        ui: 'soft-green',
        listeners: {
            click: 'onFormSubmitButton'
        }
    }]

});